package hui.zhang.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import hui.zhang.dao.transit.InOutStorageRepository;
import hui.zhang.dao.transit.TransitInfoRepository;
import hui.zhang.domain.transit.InOutStorageInfo;
import hui.zhang.domain.transit.TransitInfo;
import hui.zhang.service.transit.InOutStorageInfoService;

@Service
@Transactional
public class InOutStorageServiceImpl implements InOutStorageInfoService {

	@Autowired
	private InOutStorageRepository inOutStorageRepository;
	
	@Autowired
	private TransitInfoRepository transitInfoRepository;
	
	@Override
	public void save(InOutStorageInfo model, String transitInfoId) {
		inOutStorageRepository.save(model);
		
		// 查询TransitInfo
		TransitInfo transitInfo = transitInfoRepository
				.findOne(Integer.parseInt(transitInfoId));
		// 关联出入库信息到运输配送对象
		transitInfo.getInOutStorageInfos().add(model);
		// 修改状态
		if(model.getOperation().equals("到达网点")) {
			transitInfo.setStatus("到达网点");
			// 更新网点地址 显示配送路径
			transitInfo.setOutletAddress(model.getAddress());
		}
	}

}
